package com.starblink.brand.ui.part

import android.content.Context
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.skydoves.balloon.Balloon
import com.starblink.brand.R

class BrandAllSort(
    var context: Context?,
    private var balloon: Balloon,
    private var doFilter:(type: Int)->Unit) {
    var ivAllItem :  ImageView?=null
    var ivSortItem :  ImageView?=null
    var tvAllItem : TextView?=null
    var tvSortItem : TextView?=null

    fun handleVM(){
        val llBrandAll=balloon.getContentView().findViewById<LinearLayout>(R.id.ll_brand_all)
        val llBrandFollow=balloon.getContentView().findViewById<LinearLayout>(R.id.ll_brand_follow)
        ivAllItem=balloon.getContentView().findViewById<ImageView>(R.id.iv_all_item)
        tvAllItem=balloon.getContentView().findViewById<TextView>(R.id.tv_all_item)
        ivSortItem=balloon.getContentView().findViewById<ImageView>(R.id.iv_sort_item)
        tvSortItem=balloon.getContentView().findViewById<TextView>(R.id.tv_sort_item)

        llBrandAll.setOnClickListener {
            doFilter.invoke(1)
            setType(1)
            balloon.dismiss()
        }

        llBrandFollow.setOnClickListener {
            doFilter.invoke(2)
            setType(2)
            balloon.dismiss()
        }
    }

    fun setType(type: Int){
        when(type){
            0->{
                ivAllItem?.setImageResource(com.starblink.android.basic.R.mipmap.icon_brand_check)
                ivSortItem?.setImageResource(com.starblink.android.basic.R.mipmap.icon_brand_check)
                tvAllItem?.setTextAppearance(context,com.starblink.basic.style.R.style.Guang2_Text_Body_M)
                tvSortItem?.setTextAppearance(context,com.starblink.basic.style.R.style.Guang2_Text_Body_M)
            }
            1->{
                ivAllItem?.setImageResource(com.starblink.android.basic.R.mipmap.icon_brand_checked)
                ivSortItem?.setImageResource(com.starblink.android.basic.R.mipmap.icon_brand_check)
                tvAllItem?.setTextAppearance(context,com.starblink.basic.style.R.style.Guang2_Text_Label_M)
                tvSortItem?.setTextAppearance(context,com.starblink.basic.style.R.style.Guang2_Text_Body_M)
            }
            2->{
                ivAllItem?.setImageResource(com.starblink.android.basic.R.mipmap.icon_brand_check)
                ivSortItem?.setImageResource(com.starblink.android.basic.R.mipmap.icon_brand_checked)
                tvAllItem?.setTextAppearance(context,com.starblink.basic.style.R.style.Guang2_Text_Body_M)
                tvSortItem?.setTextAppearance(context,com.starblink.basic.style.R.style.Guang2_Text_Label_M)
            }
        }
    }
}